package top.chatgqt.SmartChargeStation.demo.websocket.servEndPoint.service;

import jakarta.websocket.*;
import jakarta.websocket.server.ServerEndpoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * WebSocket (基于Tomcat @ServerEndPoint) 服务类
 */
@Component
@Slf4j
//@ServerEndpoint("/ws/server")
public class WebSocketService {

    /*
    @ServerEndpoint修饰的类，包含：
        @Open、@Close、@OnMessage、@OnError方法

    疑问？ SpringBoot如何能将@ServerEndpoint修饰的类，注入到容器里？
        conf.ServerEndPointExp
     */
    @OnOpen
    public void onOpen() {
        log.info(">>>> ServerEndPoint 连接成功 <<<<");
    }

    @OnClose
    public void onClose() {
        log.info(">>>> 断开连接 <<<<");
    }

    @OnMessage
    public void onMessage(String message) {
        log.info(">>>> {} <<<<", message);
    }

    @OnError
    public void onError(Throwable error) {
        log.info("报错了！ {}", error.getMessage());
    }
}
